package com.inspur.gs.sbssdl.sbyxgl.djjh.djjh.front.sbxldistinct.voactions;
import com.inspur.edp.bff.api.manager.context.QueryContext;
import com.inspur.edp.bff.spi.action.query.AbstractQueryAction;
import com.inspur.edp.caf.db.dbaccess.DynamicResultRow;
import com.inspur.edp.cef.entity.entity.IEntityData;
import com.inspur.edp.qdp.bql.api.IBqlExecuter;
import io.iec.edp.caf.runtime.config.BqlBeanUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

public class sbxldistinctVOAction extends AbstractQueryAction {

	private IBqlExecuter bqlExecuter = BqlBeanUtil.getAppCtx().getBean(IBqlExecuter.class);

	public sbxldistinctVOAction(QueryContext context){
		super(context);
	}
	@Override
	public void execute() {
		List<String> entityIds = new ArrayList<String>();
		entityIds.add("33c580b1-c1fc-45fc-9771-21165a1960e0");
		String bql = "SELECT DISTINCT djjhsz.SBDL,djjhsz.SBXL FROM djjhsz.djjhsz";
		List<DynamicResultRow> resultRows=bqlExecuter.executeSelectStatement(bql,entityIds);
		ArrayList<IEntityData> entityData=new ArrayList<>();
		for(DynamicResultRow resultRow:resultRows){
			IEntityData voEntityData =getContext().createData();
			String entityDetailId = UUID.randomUUID().toString();
			voEntityData.setValue("ID",entityDetailId);
			if(resultRow.getValues().get(0) != null)
				voEntityData.setValue("sbdl",resultRow.getValues().get(1).toString());
			if(resultRow.getValues().get(1) != null)
				voEntityData.setValue("sbxl",resultRow.getValues().get(1).toString());
			entityData.add(voEntityData);
		}
		HashMap queryResult = new HashMap<String,ArrayList<IEntityData>>();
		queryResult.put("queryresult",entityData);
		setResult(queryResult);
	}
}
